package com.example.test.启动线程.买票;

public class pring {

    public static void main(String[] args) {


         class Print implements Runnable {

            private boolean flag = true;

            public void setFlag(boolean flag) {
                this.flag = flag;
            }

            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "===" + flag);
                synchronized (Print.class) {
                    if (flag) {
                        try {
                            System.out.println("累了,睡一会儿");
                            Thread.sleep(3000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        System.out.println("睡醒了");
                    } else {
                        System.out.println("人人都是程序员");
                    }
                }
            }

        }

        Print print = new Print();

        Thread thread = new Thread(print);
        thread.start();


        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        print.setFlag(false);

        Thread thread1 = new Thread(print);
        thread1.start();

    }
}
